<template>
  <div class="app-container">
    <slot :list_type="list_type"></slot>
    <div class="filter-container">
      <selectServer @server-selected="handleSelectServer" />
      <el-date-picker v-model="searchForm.startDate" class="filter-item" type="date" style="width: 160px;" placeholder="开始时间"></el-date-picker>-
      <el-date-picker v-model="searchForm.endDate" class="filter-item" type="date" style="width: 160px;" placeholder="结束时间"></el-date-picker>
      <!-- <el-input v-model="searchForm.hero_id" class="filter-item" style="width: 150px;" placeholder="英雄ID" /> -->
      <el-button class="filter-item" type="primary" plain icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" :style="{height: '780px'}" class="mt-10" border height="780">
      <el-table-column label="英雄" prop="hero_name" width="150px" align="center"></el-table-column>
      <el-table-column label="上阵人数" prop="num" width="150px" align="center"></el-table-column>
      <el-table-column label="上阵次数" prop="time" width="150px" align="center"></el-table-column>
      <el-table-column label="胜利次数" prop="success" width="150px" align="center"></el-table-column>
      <el-table-column label="胜率" prop="success_radio" width="150px" align="center"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getHeroGattleList } from '@/api/statis'
import checkPermission from '@/utils/permission'
import SelectServer from '@/components/SelectServer'
const log_type = 25
export default {
  name: 'Date',
  components: { SelectServer },
  data() {
    return {
      permissionRoles: this.$store.state.user.permissionRoles,
      list: [],
      list_type: 1,
      serverList: [],
      loading: false,
      listLoading: false,
      columns: [],
      downloadLoading: false,
      searchForm: {
        startDate: new Date(Date.now() - 86400000 * 11),
        endDate: new Date(Date.now() - 86400000 * 1),
        sid: [],
        hero_id: ''
      }
    }
  },
  computed: {
  },
  mounted() {
    console.log('Received list_type:', this.list_type) // 检查接收到的 prop 是否正确
  },
  created() {
    // this.getList()
  },
  methods: {
    checkPermission,
    handleFilter() {
      this.getList()
    },
    handleSelectServer(servers) {
      this.searchForm.servers = servers
    },
    handleChange(val) {
      // this.type = this.types[val]
    },
    getTypes() {
      const query = Object.assign({ day_type: this.list_type }, this.searchForm)
      return query
    },
    async getList() {
      this.listLoading = true
      const res = await getHeroGattleList(Object.assign({ log_type: log_type }, this.getTypes()))
      this.listLoading = false
      this.list = res.data
    },
    handleDownload() {
      this.downloadLoading = true
    },
    formatJson(filterVal) {
      return this.list.map(v => filterVal.map(j => {
        return v[j]
      }))
    }
  }
}
</script>
